import * as Cookie from '@/utils/cookie'
const Menu = {
  state: {
    menuList: {
      '内容管理': 'content',
      // '微信管理': 'wechat',
      // '会员管理': 'member',
      // '商城管理': 'shop',
      '系统管理': 'system',
      'Demo': 'demo'
    },
    drawerStatus: null,
    drawerMini: false,
    currentMenu: Cookie.getToken('currment_menu') || 'content',
    currentMenuList: []
  },
  getters: {
    menu: state => {
      return state.menuList
    }
  },
  mutations: {
    setCurrentMenu (state, menuName) {
      Cookie.setToken(menuName, 'currment_menu')
      state.currentMenu = menuName
    },
    setCurrentMenuList (state, list) {
      state.currentMenuList = list
    },
    setDrawerStatus (state, status) {
      if (status === null) {
        if (state.drawerStatus === true && state.drawerMini === false) {
          state.drawerMini = true
        } else if (state.drawerStatus === true && state.drawerMini === true) {
          state.drawerMini = false
        } else {
          state.drawerStatus = !state.drawerStatus
        }
      } else {
        state.drawerStatus = status
      }
    }
  },
  actions: {
    getCurrentMenuList ({ commit }, menuName) {
      commit('setCurrentMenu', menuName)
      return import('@/apps/admin/router/' + menuName).then(res => {
        commit('setCurrentMenuList', res.default.children)
        commit('setDrawerStatus', true)
      })
    },
    getDefaultCurrentMenuList ({ commit, state }) {
      return import('@/apps/admin/router/' + state.currentMenu).then(res => {
        commit('setCurrentMenuList', res.default.children)
      })
    }
  }
}
export default Menu
